<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}lib/ja.css" />
<link rel="stylesheet" href="${aier_css_url}jc/chosen.css">
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}text.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}enhanced.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}proxy/pae.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/ja.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}comm/text.js"></script>
<title>门禁设备</title>
</head>
<script type="text/javascript">
	$(document).ready(function() {
		$("#entranceinfo")
				.jqGrid(
						{
							url : "${aier_url}${aier_urijs}proxy_entrance_searchEntranceInfo${aier_suffix}?pid=${pid}",
							datatype : "json",
							mtype : 'GET',
							height : '230',
							width : '960',
							colNames : [ '设备编码', '状态','所属学校','设备厂家', '视频编码', '拍照状态','操作','状态','拍照状态','所属学校id','门禁id' ],
							colModel : [ 
							{name : 'sn',index : 'sn',width : 80,align : 'center'}, 
							{name : 'state_str',index : 'state_str',width : 80,align : 'center',sortable:false}, 
							{name : 'school_name',index : 'school_name',width : 80,align : 'center',sortable:false}, 
							{name : 'supplier_str',index : 'supplier_str',width : 80,align : 'center',sortable:false}, 
							{name : 'video_sn',index : 'video_sn',width : 80,align : 'center',sortable:false}, 
							{name : 'vdstate_str',index : 'vdstate_str',width : 80,align : 'center',sortable:false}, 
							{name : 'operating',index : 'operating',width : 80,align : 'center',sortable:false}, 
							{name : 'state',index:'state',hidden : true},
							{name : 'vdstate',index:'vdstate',hidden : true},
							{name : 'sid',index:'sid',hidden : true},
							{name : 'eid',index : 'eid',hidden:true}
							],
							//autowidth:true,
							jsonReader : {
								root : "eds",
								page : "page",
								total : "page_count",
								repeatitems : false
							},
							pager : jQuery("#entrancepage"),
							prmNames : {
								page : "page",
								sort : "sort"
							},
							rowNum : 10,
							//rowList: [10, 20, 30],
							sortname : 'teacherName',
							hidegrid : false,
							sortorder : 'asc',
							viewrecords : true,
							caption : '门禁设备信息',
							gridComplete : function() {
								var ids = jQuery("#entranceinfo").jqGrid('getDataIDs');
								for(var i=0; i<ids.length; i++){
							var id=ids[i];   
							var state = jQuery("#entranceinfo").jqGrid('getRowData', id).state;
							if (state == 0 || state == 10) {
										re = "<a href='javascript:;' class='jqtrow' onclick='setVedio(" + id + ")'>设置</a>"; 
									} else {
										re = "<a href='javascript:;' class='jqtrow' onclick='delVedio(" + id + ")'>删除</a>"; 
									}
									jQuery("#entranceinfo").jqGrid('setRowData', ids[i], {operating:re});
								}
							}
						}).navGrid("#entrancepage", {
					edit : false,
					add : false,
					del : false,
					search : false
				});
	});

//查询
function search(){
		
		//设备编号
		var info_sn = $("#txt_sn").val();
		//派属
		var info_poxystate = $("#sel_eassign").val();
		//设备状态
		var info_state = $("#sel_estate").val();
		//所属学校
		var info_sid = $("#sel_eschool").val();
		jQuery("#entranceinfo").jqGrid('setGridParam',{url:"${aier_url}${aier_urijs}proxy_entrance_searchEntranceInfo${aier_suffix}?sn="+info_sn+"&state="+info_state
			+"&poxystate="+info_poxystate+"&sid="+info_sid+"&pid=${pid}",page:1}).trigger("reloadGrid");
			
	}
	
//设置
var eid="";
function setVedio(id) {
	eid = jQuery("#entranceinfo").jqGrid('getRowData', id).eid;
	$("#span_upsn").html(jQuery("#entranceinfo").jqGrid('getRowData', id).sn);
	$("#span_supplier").html(jQuery("#entranceinfo").jqGrid('getRowData', id).supplier_str);
	$("#sel_upestate").val(jQuery("#entranceinfo").jqGrid('getRowData', id).state);
	$("#sel_upevdstate").val(jQuery("#entranceinfo").jqGrid('getRowData', id).vdstate);
	$("#d_upEinfo").dialog("open");
	var sid = jQuery("#entranceinfo").jqGrid('getRowData', id).sid;
	var fun=function(data){
	var t="<select style='border-color: #45930b;' id='sel_upschool'><option value='-1'>无</option>";
		if(!isnull(data.schoolsList) && data.schoolsList.length>0){
				for ( var i = 0; i < data.schoolsList.length; i++) {
					var school = data.schoolsList[i];
					t += "<option value="+school.sid+">" + school.name + "</option>";
				}
				
			};
			t += "</select>";
			$('#d_upeschool').html(t);
			if(!isnull(sid)){
			$("#sel_upschool").find("option[value='"+sid+"']").attr("selected", "selected");
			}
			
	};
	exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_entrance_selschools${aier_suffix}"),
				fun, {
					"pid" : "${pid}"
				});
				
	
	
}

// 删除报废设备
	function delVedio(id){
		if (!confirm("确定要删除该设备吗？")) {
			return
		} else {
			var fun = function(data) {
				if(10001==data.s){
					$().message("删除成功!");
					$("#entranceinfo").trigger("reloadGrid");
				}else{
					$().message("删除失败!");
				}
			};
			exeAjax(ajaxUrl("${aier_url}${aier_urijs}proxy_entrance_pec_delete${aier_suffix}"), fun, 
			{"eid" : jQuery("#entranceinfo").jqGrid('getRowData', id).eid});
		}
			
	}

//弹出层更新按钮事件
function updateLoad() {
		var fun = function(data) {
			if (data.s == 10001) {
				$().message("设置成功");
				$("#d_upEinfo").dialog("close");
				$("#entranceinfo").trigger("reloadGrid");
			} else{
				$().message("修改失败");
			}
		};
		exeAjax(
			ajaxUrl("${aier_url}${aier_urijs}proxy_entrance_pec_update${aier_suffix}"),
			fun, {
				"eid" : eid,
				"state":$('#sel_upestate').val(),
				"vdstate":$('#sel_upevdstate').val(),
				"sid":$('#sel_upschool').val()
				
			});
	}

</script>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">门禁设备</a>
			</li>
		</ul>
		<div id="tabs-1" style="height: 500px;">
			<div class="d_content">
				<div class="d_scnOut">
					<div class="d_scname">
						<label for="txt_sn">设备编码:</label>
					</div>
					<div class="d_sctext">
						<input id="txt_sn" type="text">
					</div>
				</div>
				<div class="d_scnOut">
					<div class="d_scname">
						<label for="sel_eassign">派属:</label>
					</div>
					<div class="sel_region">
						<select id="sel_eassign">
							<option value="-1">不限</option>
							<option value="1">未分派</option>
							<option value="2">已分派</option>
						</select>
					</div>
				</div>
				<div style="margin-left: 300px;margin-top: -80px;">
					<div class="d_scnOut">
						<div class="d_scname">
							<label for="sel_estate">状态:</label>
						</div>
						<div class="sel_region">
							<select id="sel_estate">
								<option value="-1">不限</option>
								<option value="10">启用</option>
								<option value="0">停用</option>
								<option value="-10">报废</option>
							</select>
						</div>
					</div>
					<div class="d_scnOut">
						<div class="d_scname">
							<label for="sel_eschool">所属学校:</label>
						</div>
						<div class="sel_region">
							<select id="sel_eschool" class="chosen" style="width:150px;" tabindex="4">
								<option value="-1">请选择</option>
								<c:forEach var="sg" items="${schoolsList}">
									<option value="${sg.sid}">${sg.name}</option>
								</c:forEach>
							</select>

						</div>
					</div>

				</div>
				<div style="margin-left: 660px;margin-top: -45px;">
					<button onclick="search()"
						class="b_maSel ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">查询</span>
					</button>
				</div>
				<!-- 表格 -->
				<div style="margin-top: 30px;">
					<table id="entranceinfo"></table>
					<div id="entrancepage"></div>
				</div>
				<!-- 弹出层 -->
				<div id="d_upEinfo" title="门禁信息" style="font-size:14px;">
					<div class="d_scnOut">
						<div class="d_scname">
							<label>门禁设备:</label>
						</div>
						<div class="d_sctext">
							<span id="span_upsn"></span>
						</div>
					</div>
					<div class="d_scnOut">
						<div class="d_scname">
							<label for="sel_upestate">状态:</label>
						</div>
						<div class="sel_region">
							<select id="sel_upestate">
								<option value="10">启用</option>
								<option value="0">停用</option>
								<option value="-10">报废</option>
							</select>
						</div>
					</div>
					
					<div class="d_scnOut">
						<div class="d_scname">
							<label for="sel_upevdstate">拍照状态:</label>
						</div>
						<div class="sel_region">
							<select id="sel_upevdstate">
								<option value="0">不拍照</option>
								<option value="1">出门拍照</option>
								<option value="10">进门拍照</option>
								<option value="11">都拍照</option>
							</select>
						</div>
					</div>
					<div style="margin-left: 285px;margin-top: -120px;">
						<div class="d_scnOut">
							<div class="d_scname">
								<label>设备厂商:</label>
							</div>
							<div class="d_sctext">
								<span id="span_supplier"></span>
							</div>
						</div>
						<div class="d_scnOut">
							<div class="d_scname">
								<label>所属学校:</label>
							</div>
							<div id="d_upeschool" class="sel_region">
								
							</div>
						</div>
					</div>
					
					<button id="b_siUpdate"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false"
						style="left: 300px; top: 110px;" onclick="updateLoad();">
						<span class="ui-button-text">修改</span>
					</button>				
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$("#tabs").tabs();
	$(".chosen").chosen();
	
	// 弹出层
$(function() {

	$("#d_upEinfo").dialog({
		//背景变暗
		modal : true,
		autoOpen : false,
		show : "blind",
		//hide : "explode",
		width : "600",
		height : "300"
	});

});

</script>
</html>